package com.etone.smartAudit.service;

import com.etone.smartAudit.enums.TaskType;
import com.etone.smartAudit.mapper.OfficeMapper;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.office.OfficeBaseVO;
import com.etone.smartAudit.vo.office.OfficeListVO;
import com.etone.smartAudit.vo.source.SourceSimpleVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author: 蒋学伟
 * @create: 2020-06-28 14:19:47
 * @Description OfficeService
 */
@Service
@AllArgsConstructor
public class OfficeService {
    private OfficeMapper officeMapper;

    /**
     * 超级本/工作站信息
     *
     * @param type
     * @return
     */
    public SourceSimpleVO findOneByType(TaskType type) {
        return officeMapper.findOneByType(type);
    }

    /**
     * 临时资源信息
     *
     * @param page
     * @param pageSize
     * @return
     */
    public PagerVO<SourceSimpleVO> findTemporarySource(int page, int pageSize) {
        Page<SourceSimpleVO> sourceSimpleVOS = PageHelper.startPage(page, pageSize).doSelectPage(() -> {
            officeMapper.findTemporarySource();
        });
        return PagerVO.of(sourceSimpleVOS);
    }

    /**
     * 事务所基本信息列表
     *
     * @param type
     * @param keys
     * @param page
     * @param pageSize
     * @return
     */
    public PagerVO<OfficeBaseVO> listSimple(String keys, String type, int page, int pageSize) {
        Page<OfficeBaseVO> officeBaseVOPage = PageHelper.startPage(page, pageSize).doSelectPage(() -> {
            officeMapper.listSimple(keys, type);
        });
        return PagerVO.of(officeBaseVOPage);
    }

    /**
     * 事务所列表
     *
     * @param name
     * @param type
     * @param startTime
     * @param endTime
     * @param page
     * @param pageSize
     * @return
     */
    public PagerVO<OfficeListVO> list(String name, String type, Date startTime, Date endTime, int page, int pageSize) {
        Page<OfficeListVO> officeListVOPage = PageHelper.startPage(page, pageSize).doSelectPage(() -> {
            officeMapper.findList(name, type, startTime, endTime);
        });
        return PagerVO.of(officeListVOPage);
    }
}
